﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ProductManager_ReturnCashRecords : System.Web.UI.Page
{
    GoShopping.BLL.Orders.OrderBean ordBean = new GoShopping.BLL.Orders.OrderBean();
    GoShopping.BLL.Orders.ReturnCashRecordsBean rcrBean = new GoShopping.BLL.Orders.ReturnCashRecordsBean();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["ID"] != null)
            {
                hidOrderId.Value = Request.QueryString["ID"].ToString();
                InitialPage();
            }
        }
    }

    private void InitialPage()
    {
        GoShopping.Model.Order ord = ordBean.GetOneOrder(Convert.ToInt32(Request.QueryString["ID"]));
        lblReCashCode.Text = "无";
        lblOrderCode.Text = ord.OrderCode;
        lblDate.Text = DateTime.Now.ToString();
        lblReCashDealer.Text = Context.User.Identity.Name;
        lblReCashMember.Text = ord.UserName;
        lblReStatus.Text = "未退款";
        lblReTotalPrice.Text = (ord.TotalPrice + ord.PostPrice).ToString();
        lblReCashAddr.Text = ord.Province + ord.City + ord.County + ord.DetailStreet;

        //txtReType.Text;
        //txtRePrdtBankAccount.Text;
        //txtReCashBank.Text;
        //txtMoneyType.Text;
        //txtHandler.Text;
        //txtComment.Text;
    }


    protected void btnComplete_Click(object sender, EventArgs e)
    {
        //保存到数据库
        GoShopping.Model.ReturnCashRecords rcr = new GoShopping.Model.ReturnCashRecords();
        //lblReCashCode.Text;
        rcr.OrderID=lblOrderCode.Text;
        rcr.ReturnDate=Convert.ToDateTime(lblDate.Text);
        rcr.RecordPerson=lblReCashDealer.Text;
        rcr.UserName=lblReCashMember.Text;
        rcr.Status=lblReStatus.Text;
        rcr.TotalPrice=Convert.ToDecimal(lblReTotalPrice.Text);
        rcr.UserAddress=lblReCashAddr.Text;

        rcr.ReturnCashType=txtReType.Text;
        rcr.ReturnCashAccount=txtRePrdtBankAccount.Text;
        rcr.ReturnCashBank=txtReCashBank.Text;
        rcr.MoneyType=txtMoneyType.Text;
        rcr.Returner=txtHandler.Text;
        rcr.Remark = txtComment.Text;
        //插入数据
        rcrBean.Insert(rcr);
        //更新状态
        ordBean.UpdateOrder(Convert.ToInt32(Request.QueryString["ID"]), GoShopping.Model.Enumerations.OrderStatusType.ReturnCash);
        //跳转到Detail
        Response.Redirect("OrderDetail.aspx?ID=" + Request.QueryString["ID"]);
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {   
        //跳转到Detail
        Response.Redirect("OrderDetail.aspx?ID=" + hidOrderId.Value);
    }
}
